﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class admin_SelectClient : System.Web.UI.Page
{
    static PagedDataSource pagedDataSource = new PagedDataSource();
    static List<Client> list = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Client client = new Client();
            client.IsShare = 2;
            TarreOA.TarreOAModels.User user = (User)Session["user"];
            if (user.ShellManager==0)
            {
                client.SellUser = user;
            }
            else
            {
                TarreOA.TarreOAModels.User user1 = new User();
                user1.UserId = 0;
                client.SellUser = user1;
            }
            list = ClientManager.FindBlurClient(client);
            pagedDataSource.DataSource = list;
            pagedDataSource.PageSize = 10;
            pagedDataSource.CurrentPageIndex = 0;
            pagedDataSource.AllowPaging = true;
            this.DataList1.DataSource = pagedDataSource;
            this.DataList1.DataBind();
        }
    }
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "selectData")
        {
            Client client = ClientManager.FindByClientId(Convert.ToInt32(e.CommandArgument.ToString()));
            ClientScript.RegisterStartupScript(this.GetType(), "", "var rel=new Array('" + e.CommandArgument.ToString() + "','" + client.ClientName + "'); window.returnValue = rel; window.close();", true);
        }
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            if (pagedDataSource.IsFirstPage)
            {
                ((LinkButton)e.Item.FindControl("LinkButton2")).Enabled = false;
            }
            if (pagedDataSource.IsLastPage)
            {
                ((LinkButton)e.Item.FindControl("LinkButton3")).Enabled = false;
            }
        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        pagedDataSource.DataSource = list;
        pagedDataSource.PageSize = 10;
        pagedDataSource.AllowPaging = true;
        pagedDataSource.CurrentPageIndex--;
        DataList1.DataSource = pagedDataSource;
        DataList1.DataBind();
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        pagedDataSource.DataSource = list;
        pagedDataSource.PageSize = 10;
        pagedDataSource.AllowPaging = true;
        pagedDataSource.CurrentPageIndex++;
        DataList1.DataSource = pagedDataSource;
        DataList1.DataBind();
    }
    protected void btnFind_Click(object sender, EventArgs e)
    {
        if (txtClientName.Text != null && txtClientName.Text != "")
        {
            Client client = new Client();
            client.ClientName = txtClientName.Text.Trim();
            client.IsShare = 2;
            TarreOA.TarreOAModels.User user = (User)Session["user"];
            if (user.ShellManager == 0)
            {
                client.SellUser = user;
            }
            else
            {
                TarreOA.TarreOAModels.User user1 = new User();
                user1.UserId = 0;
                client.SellUser = user1;
            }
            list = ClientManager.FindBlurClient(client);
            pagedDataSource.DataSource = list;
            pagedDataSource.PageSize = 10;
            pagedDataSource.CurrentPageIndex = 0;
            pagedDataSource.AllowPaging = true;
            this.DataList1.DataSource = pagedDataSource;
            this.DataList1.DataBind();
        }
    }
}
